package ss12.MobileColorIdentifier.Image;
import java.util.*;
import android.graphics.*;

/**@author Stephen
 */
public class HexToStringConverter {
	private HashMap<Integer, String> colors;
	public HexToStringConverter(){
		populateHashMap();
	}
	/**
	 * Color Table
	 */
	private void populateHashMap(){
		colors = new HashMap<Integer, String>();
		/*
		colors.put(new Integer(0xFF0000), "Red");
		colors.put(new Integer(0xFFA500), "Orange");
		colors.put(new Integer(0xFFFF00), "Yellow");
		colors.put(new Integer(0xFF00FF), "Magenta");
		colors.put(new Integer(0x008000), "Green");
		colors.put(new Integer(0x0000FF), "Blue");
		colors.put(new Integer(0x800080), "Purple");
		colors.put(new Integer(0xFFFFFF), "White");
		colors.put(new Integer(0x000000), "Black");
		colors.put(new Integer(0x888888), "Grey");
		colors.put(new Integer(0x00FF00), "Lime");
		colors.put(new Integer(0x854513), "Brown");
		colors.put(new Integer(0xFFC0CB), "Pink");
		colors.put(new Integer(0x006400), "Dark Green");
		colors.put(new Integer(0x00FFFF), "Cyan");
		*/
		colors.put(new Integer(0xCD5C5C), "IndianRed");
		colors.put(new Integer(0xF08080), "LightCoral");
		colors.put(new Integer(0xFA8072), "Salmon");
		colors.put(new Integer(0xE9967A), "DarkSalmon");
		colors.put(new Integer(0xFFA07A), "LightSalmon");
		colors.put(new Integer(0xDC143C), "Crimson");
		colors.put(new Integer(0xFF0000), "Red");
		colors.put(new Integer(0xB22222), "FireBrick");
		colors.put(new Integer(0x8B0000), "DarkRed");
		colors.put(new Integer(0xFFC0CB), "Pink");
		colors.put(new Integer(0xFFB6C1), "LightPink");
		colors.put(new Integer(0xFF69B4), "HotPink");
		colors.put(new Integer(0xFF1493), "DeepPink");
		colors.put(new Integer(0xC71585), "MediumVioletRed");
		colors.put(new Integer(0xDB7093), "PaleVioletRed");
		colors.put(new Integer(0xFFA07A), "LightSalmon");
		colors.put(new Integer(0xFF7F50), "Coral");
		colors.put(new Integer(0xFF6347), "Tomato");
		colors.put(new Integer(0xFF4500), "OrangeRed");
		colors.put(new Integer(0xFF8C00), "DarkOrange");
		colors.put(new Integer(0xFFA500), "Orange");
		colors.put(new Integer(0xFFD700), "Gold");
		colors.put(new Integer(0xFFFF00), "Yellow");
		colors.put(new Integer(0xFFFFE0), "LightYellow");
		colors.put(new Integer(0xFFFACD), "LemonChiffon");
		colors.put(new Integer(0xFAFAD2), "LightGoldenrodYellow");
		colors.put(new Integer(0xFFEFD5), "PapayaWhip");
		colors.put(new Integer(0xFFE4B5), "Moccasin");
		colors.put(new Integer(0xFFDAB9), "PeachPuff");
		colors.put(new Integer(0xEEE8AA), "PaleGoldenrod");
		colors.put(new Integer(0xF0E68C), "Khaki");
		colors.put(new Integer(0xBDB76B), "DarkKhaki");
		colors.put(new Integer(0xE6E6FA), "Lavender");
		colors.put(new Integer(0xD8BFD8), "Thistle");
		colors.put(new Integer(0xDDA0DD), "Plum");
		colors.put(new Integer(0xEE82EE), "Violet");
		colors.put(new Integer(0xDA70D6), "Orchid");
		colors.put(new Integer(0xFF00FF), "Fuchsia");
		colors.put(new Integer(0xFF00FF), "Magenta");
		colors.put(new Integer(0xBA55D3), "MediumOrchid");
		colors.put(new Integer(0x9370DB), "MediumPurple");
		colors.put(new Integer(0x9966CC), "Amethyst");
		colors.put(new Integer(0x8A2BE2), "BlueViolet");
		colors.put(new Integer(0x9400D3), "DarkViolet");
		colors.put(new Integer(0x9932CC), "DarkOrchid");
		colors.put(new Integer(0x8B008B), "DarkMagenta");
		colors.put(new Integer(0x800080), "Purple");
		colors.put(new Integer(0x4B0082), "Indigo");
		colors.put(new Integer(0x6A5ACD), "SlateBlue");
		colors.put(new Integer(0x4B0082), "ndigo");
		colors.put(new Integer(0x6A5ACD), "SlateBlue");
		colors.put(new Integer(0x483D8B), "DarkSlateBlue");
		colors.put(new Integer(0x7B68EE), "MediumSlateBlue");
		colors.put(new Integer(0xADFF2F), "GreenYellow");
		colors.put(new Integer(0x7FFF00), "Chartreuse");
		colors.put(new Integer(0x7CFC00), "LawnGreen");
		colors.put(new Integer(0x00FF00), "Lime");
		colors.put(new Integer(0x32CD32), "LimeGreen");
		colors.put(new Integer(0x98FB98), "PaleGreen");
		colors.put(new Integer(0x90EE90), "LightGreen");
		colors.put(new Integer(0x00FA9A), "MediumSpringGreen");
		colors.put(new Integer(0x00FF7F), "SpringGreen");
		colors.put(new Integer(0x3CB371), "MediumSeaGreen");
		colors.put(new Integer(0x2E8B57), "SeaGreen");
		colors.put(new Integer(0x228B22), "ForestGreen");
		colors.put(new Integer(0x008000), "Green");
		colors.put(new Integer(0x006400), "DarkGreen");
		colors.put(new Integer(0x9ACD32), "YellowGreen");
		colors.put(new Integer(0x6B8E23), "OliveDrab");
		colors.put(new Integer(0x808000), "Olive");
		colors.put(new Integer(0x556B2F), "DarkOliveGreen");
		colors.put(new Integer(0x66CDAA), "MediumAquamarine");
		colors.put(new Integer(0x8FBC8F), "DarkSeaGreen");
		colors.put(new Integer(0x20B2AA), "LightSeaGreen");
		colors.put(new Integer(0x008B8B), "DarkCyan");
		colors.put(new Integer(0x008080), "Teal");
		colors.put(new Integer(0x00FFFF), "Aqua");
		colors.put(new Integer(0x00FFFF), "Cyan");
		colors.put(new Integer(0xE0FFFF), "LightCyan");
		colors.put(new Integer(0xAFEEEE), "PaleTurquoise");
		colors.put(new Integer(0x7FFFD4), "Aquamarine");
		colors.put(new Integer(0x40E0D0), "Turquoise");
		colors.put(new Integer(0x48D1CC), "MediumTurquoise");
		colors.put(new Integer(0x00CED1), "DarkTurquoise");
		colors.put(new Integer(0x5F9EA0), "CadetBlue");
		colors.put(new Integer(0x4682B4), "SteelBlue");
		colors.put(new Integer(0xB0C4DE), "LightSteelBlue");
		colors.put(new Integer(0xB0E0E6), "PowderBlue");
		colors.put(new Integer(0xADD8E6), "LightBlue");
		colors.put(new Integer(0x87CEEB), "SkyBlue");
		colors.put(new Integer(0x87CEFA), "LightSkyBlue");
		colors.put(new Integer(0x00BFFF), "DeepSkyBlue");
		colors.put(new Integer(0x1E90FF), "DodgerBlue");
		colors.put(new Integer(0x6495ED), "CornflowerBlue");
		colors.put(new Integer(0x7B68EE), "MediumSlateBlue");
		colors.put(new Integer(0x4169E1), "RoyalBlue");
		colors.put(new Integer(0x0000FF), "Blue");
		colors.put(new Integer(0x0000CD), "MediumBlue");
		colors.put(new Integer(0x00008B), "DarkBlue");
		colors.put(new Integer(0x000080), "Navy");
		colors.put(new Integer(0x191970), "MidnightBlue");
		colors.put(new Integer(0xFFF8DC), "Cornsilk");
		colors.put(new Integer(0xFFEBCD), "BlanchedAlmond");
		colors.put(new Integer(0xFFE4C4), "Bisque");
		colors.put(new Integer(0xFFDEAD), "NavajoWhite");
		colors.put(new Integer(0xF5DEB3), "Wheat");
		colors.put(new Integer(0xDEB887), "BurlyWood");
		colors.put(new Integer(0xD2B48C), "Tan");
		colors.put(new Integer(0xBC8F8F), "RosyBrown");
		colors.put(new Integer(0xF4A460), "SandyBrown");
		colors.put(new Integer(0xDAA520), "Goldenrod");
		colors.put(new Integer(0xB8860B), "DarkGoldenrod");
		colors.put(new Integer(0xCD853F), "Peru");
		colors.put(new Integer(0xD2691E), "Chocolate");
		colors.put(new Integer(0x8B4513), "SaddleBrown");
		colors.put(new Integer(0xA0522D), "Sienna");
		colors.put(new Integer(0xA52A2A), "Brown");
		colors.put(new Integer(0x800000), "Maroon");
		colors.put(new Integer(0xFFFFFF), "White");
		colors.put(new Integer(0xFFFAFA), "Snow");
		colors.put(new Integer(0xF0FFF0), "Honeydew");
		colors.put(new Integer(0xF5FFFA), "MintCream");
		colors.put(new Integer(0xF0FFFF), "Azure");
		colors.put(new Integer(0xF0F8FF), "AliceBlue");
		colors.put(new Integer(0xF8F8FF), "GhostWhite");
		colors.put(new Integer(0xF5F5F5), "WhiteSmoke");
		colors.put(new Integer(0xFFF5EE), "Seashell");
		colors.put(new Integer(0xF5F5DC), "Beige");
		colors.put(new Integer(0xFDF5E6), "OldLace");
		colors.put(new Integer(0xFFFAF0), "FloralWhite");
		colors.put(new Integer(0xFFFFF0), "Ivory");
		colors.put(new Integer(0xFAEBD7), "AntiqueWhite");
		colors.put(new Integer(0xFAF0E6), "Linen");
		colors.put(new Integer(0xFFF0F5), "LavenderBlush");
		colors.put(new Integer(0xFFE4E1), "MistyRose");
		colors.put(new Integer(0xDCDCDC), "Gainsboro");
		colors.put(new Integer(0xD3D3D3), "LightGrey");
		colors.put(new Integer(0xC0C0C0), "Silver");
		colors.put(new Integer(0xA9A9A9), "DarkGray");
		colors.put(new Integer(0x808080), "Gray");
		colors.put(new Integer(0x696969), "DimGray");
		colors.put(new Integer(0x778899), "LightSlateGray");
		colors.put(new Integer(0x708090), "SlateGray");
		colors.put(new Integer(0x2F4F4F), "DarkSlateGray");
		colors.put(new Integer(0x000000), "Black");
	}
	
	/**
	 * takes a int color and returns the name of the color
	 * @param rgbColor
	 * @return
	 */
	public String getColorName(int rgbColor){
		int dr, dg, db;
		int closestColor = 0;
		int closestDistance = 1000000;
		int r = Color.red(rgbColor);
		int g = Color.green(rgbColor);
		int b = Color.blue(rgbColor);
		float distance;
		for(Integer i: colors.keySet()){
			//dr = Math.abs(Color.red(i.intValue()) - r);
			//dg = Math.abs(Color.green(i.intValue()) - g);
			//db = Math.abs(Color.blue(i.intValue()) - b);
			dr = Color.red(i.intValue()) - r;
			dg = Color.green(i.intValue()) - g;
			db = Color.blue(i.intValue()) - b;
			distance = dr * dr + dg * dg + db * db;
			if(distance < closestDistance){
				closestDistance = (int)distance;
				closestColor = i.intValue();
			}
			
		}
		return colors.get(closestColor);
	}
}


